package csloader.requests
{
	import flash.net.URLRequest;

	public class QueueRequest extends ProxyRequest
	{
		public function QueueRequest(callback:Function)
		{
			super(callback);
		}

		/**
		 * 等待中的请求
		 * @return 
		 * 
		 */		
		public function get waitingQuerys():uint
		{
			return querys.length;
		}
		
		/**
		 * 请求队列
		 */
		protected var querys:Vector.<URLRequest> = new Vector.<URLRequest>();

		public override function sendRequest(request:URLRequest) : void
		{
			querys.push(request);
			
			if(querys.length <= 1)
			{
				super.sendRequest(querys[0]);
			}
		}
		
		public override function dispose() : void
		{
			super.dispose();
			
			querys.shift();
			if(querys.length >= 1)
			{
				super.sendRequest(querys[0]);
			}
		}
		
	}
}